package main

import "fmt"

/**** 函数 ****/
func main() {
	//有返回值
	b := Myfunc01(1)
	fmt.Println("b=", b)

	c := Myfunc02(2)
	fmt.Println("c=", c)

	d := Myfunc02(3)
	fmt.Println("d=", d)

	e, f, g := Myfunc04(1)
	fmt.Printf("e=%v,f=%v,g=%v\n", e, f, g)

	h, i, j := Myfunc05(1)
	fmt.Printf("h=%v,i=%v,j=%v\n", h, i, j)

	max, min := MaxAndMin(10, 30)
	fmt.Printf("max=%v,min=%v\n", max, min)

	max1, min1 := MaxAndMin(60, 30)
	fmt.Printf("max1=%v,min1=%v\n", max1, min1)
}

//普通写法
func Myfunc01(a int) int {
	a = a + 1
	return a
}

//go 推荐写法1
func Myfunc02(a int) (ret int) {
	ret = a + 1
	return
}

//go推荐写法2
func Myfunc03(a int) (ret int) {
	ret = a + 1
	return ret
}

//多个返回值
func Myfunc04(p int) (int, int, int) {
	a := p + 1
	b := p + 2
	c := p + 3
	return a, b, c
}

//多个返回值 go官方推荐
func Myfunc05(p int) (a int, b int, c int) {
	a = p + 1
	b = p + 2
	c = p + 3
	return
}

func MaxAndMin(a, b int) (max, min int) {
	if a > b {
		max = a
		min = b
	} else {
		max = b
		min = a
	}
	return max, min
}
